// now for the AJAX stuff .... first we need an XMLHTTP object var http = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http = new XMLHttpRequest(); if (http.overrideMimeType) { http.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } } } if (!http) { alert('Cannot create an XMLHTTP instance'); } function initContextMenu() { // check whether user is logged into CMS and if so, create a DIV to display // the link to the CMS mini-menu if the DIV doesn't already exist if (loggedIntoCMS()) { if (!document.getElementById('contextHeaderDiv')) { // for menu toggling, put // around the .. below and change the showOrHideMenu() document.body.insertAdjacentHTML("afterBegin", "
\
CMS MENU
(Only shows for CMS users)
\ \ \ \
"); showOrHideMenu(); } } } function toggleHelp() { if (helpText.style.display=="none") { helpText.style.display="block"; helpText.focus(); helpLink.style.display="none"; } else { helpText.style.display="none"; helpLink.style.display="block"; } } function showOrHideMenu() { var divToShow, getMenuContents; divToShow = document.getElementById('contextMenuDiv'); // changed to remove possibility of menu toggling // to put it back, uncommment below and add onclick handler back in initContextMenu function // if (divToShow.style.display=="none") { getMenuContents = menuHTML(); divToShow.style.display="block"; divToShow.focus(); // } else { // divToShow.style.display="none"; // } } function menuHTML() { // send request to Perl script, forwarding URL parameters, and await returned result try { http.open('GET','?ajaxModule=1&mode=getContextMenu&'+window.top.location.search.substring(1),true); http.onreadystatechange = showContextMenu; http.send(null); } catch(e) { alert('failed to do http open'); } } function showContextMenu() { try { if(http.readyState == 4){ if (http.status == 200){ var response = http.responseText; document.getElementById('contextMenuDiv').innerHTML = response; } else { alert("There was a problem with the AJAX request, http status = "+http.status); } } } catch(e) { alert('showContextMenu never ready '); } } function showInCMS(URL){ // called when context menu item is clicked, to open URL in content2 frame of CMS window winHandle = window.open('','CMSWINDOW'); if(winHandle.content2) { // CMS window is there, but ensure user is still logged in!!! if (loggedIntoCMS()) { winHandle.content2.location.href = URL; } else { alert("You are not logged into the CMS!!"); } } else { winHandle.close(); alert("CMS window is not open!!"); } } function loggedIntoCMS() { if (document.cookie.indexOf("CookieUserToken") != -1) { if (readCookie("CookieUserToken")) { return 1; } } return null; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function changeCity() { // keep this here for now as an example of how to encode the URL parameters properly try { http.open('GET', '?targetModule=users&mode=getDealers&dealerCity='+encodeURIComponent(document.getElementById('dealerCity').value),true); http.onreadystatechange = showDealers; http.send(null); } catch(e) { } }